package com.longcai.util;

import com.longcai.bean.RedisUtil;
import com.longcai.entity.customer.ClyjUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TokenUtils {

    public static final Logger logger = LoggerFactory.getLogger(TokenUtils.class);

    @Autowired
    private RedisUtil redisUtil;

    /**
     * 校验登陆用户
     * @param token
     * @return
     */
    public ClyjUser Itoken(String token) {
        try {
            boolean b = redisUtil.exists(token);
            if (b == true) {
                ClyjUser clyjUser = (ClyjUser) redisUtil.get(token);
                return clyjUser;
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取登陆用户失败，请重新尝试", e);
        }
        return null;
    }
}
